import React,{Component} from 'react';
import ReactDOM from 'react-dom';
let { observable, observe, computed, autorun, when, action ,spy} = require("mobx");
import { observer} from "mobx-react"

//spy(event=>console.log(event)) //会把所的有监听出来
class Store {
    @observable todos = [];
    disposers = []; //里面放着所以取消的监听函数
    constructor(){ 
        //监听一层 只监听有变化的
        observe (this.todos,event =>{
            console.log(event)
            this.disposers.map(disposers=> disposers());
            this.disposers = [];
            for(let todo of event.object){
               let disposers =  observe(todo,e=>{
                   console.log(e);
                })
                this.disposers.push(disposers)
            }
        });
    }
}
let store = new Store();
store.todos.push({id:"2",name:"mobx"});

store.todos.push({id:"2",name:"5668898"})
store.todos.get(0).name ="cheng"
console.log(store.todos.get(0)); //获取数组第一个

// class Todos extends Component{

// }


// @observer
// ReactDOM.render(<div>
//    <Todos />
// </div>,
// document.querySelector("#app"))